## Happy Hare MMU hardware config file with config for unknown
##
## Common external mcus:
## 1) EASY-BRD
##  J6 Jumper setting
##   Option 1: Pins 2-3 and 4-5, i.e.  .[..][..] (recommended)
##   This allows for option of "touch" selector setup. Note that this enables the option disables the "extra"
##   switch so the toolhead sensor (if used) would have to be connected to the main mcu
##
##   Option 2: Pins 1-2 and 4-5, i.e.  [..].[..]
##   It you don't care about selector touch operation. The "extra" switch is enabled for other uses
##
##  Note that the EASY-BRD does not expose the DIAG pin for the gear stepper
##
## 2) Fysetc Burrows ERB
##  No jumper configuration is required for Fysetc Burrows ERB board. Both Selector and Gear DIAG pins are exposed
##
##  ERB firmware flashing notes:
##   Must have 12v/24v supply connected
##    > make menuconfig (rpi2040, No bootloader)
##    > make
##  Put card in boot loader mode: Press & Hold 'BOOTSEL' ; click 'RST; ; Release 'BOOTSEL'
##    > make flash FLASH_DEVICE=2e8a:0003
##
## ------
##
## Note about "touch" endstops: Happy Hare provides extremely flexible homing options using both single steppers or synced steppers.
## The "touch" option leverages stallguard and thus requires the appropriate 'diag_pin' and stallguard parameters set on the TMC driver
## section.  If you have the diag_pin exposed, it is harmless to define this because they will only be used when explicitly needed
## and configured.
##
## Touch option for each stepper provides these benefits / possibilities (experimental):
##  - on extruder stepper allows for the automatic detection of the nozzle!
##  - on selector stepper allows for the automatic detection of filament stuck in the gate and subsequent recovery
##  - on gear stepper allows for the automatic detection of the extruder entrance
##
## These sound wonderful right?  They are, but there are caveats:
##  - The external EASY-BRD and ERB mcu's are terrible at detecting stallguard and often result in an "undervoltage error". It is generally
##    possible to get selector touch (TMC2209) tuned especially if you set 'stealthchop_threshold' to a value greater than homing speeds and
##    less than move speed. I.e. the stepper runs in stealthchop mode when homing. [klipper experts will know that it switches the chip mode
##    automatically to stealthchop and then back for Stallguard2 support, howver the automatic switching back to spreadcycle at the end homing
##    move seems to provoke the error condition and setting 'shealthchip_threshold' appropriately avoids this condition. More than you wanted
##    to know I'm sure!
##  - I have not had much luck with touch (stallguard) on the gear stepper with EASY-BRD and ERB mcu's and you really want the extra torque
##    of spreadcycle so adjusting 'stealthchop_threshold' is not really an option
##  - Enabling on the extruder stepper is viable but you will likley have to change jumpers on your main mcu to expose the DIAG pin for
##    whichever driver the extruder stepper is connected to.
##
## In summary, "touch" homing with your MMU is an advanced option that requires patience and careful tuning.  Luckily everything works with
## regular endstops and there are workaround options for certain homing points (like extruder entry) in the absence of any endstop.
## I'm really interested in creative setups that you come up with. Ping me on Discord (moggieuk#6538)
##
##
## See mmu.cfg for serial definition and pins aliaes
##


# HOMING CAPABLE EXTRUDER (VERY ADVANCED) ----------------------------------------------------------------------------------
# With Happy Hare installed the extruder can be homed.  You will find the usual 'endstop' parameters can be added to your
# '[extruder]' section.  Useless you have some clever load cell attached to your nozzle it only really makes sense to configure 
# stallguard style "touch" homing. To do this add lines similar to this to your existing '[extruder]' definition whether
# you have it defined in printer.cfg.
#
#    [extruder]
#    endstop_pin: tmc2209_extruder:virtual_endstop
#
# Also be sure to add the appropriate stallguard config to the TMC section, e.g.
#
#    [tmc2209 extruder]
#    diag_pin: E_DIAG			# Set to MCU pin connected to TMC DIAG pin for extruder
#    driver_SGTHRS: 100			# 255 is most sensitive value, 0 is least sensitive
#
# Happy Hare will take care of the rest and add a 'mmu_ext_touch' endstop automatically


# FILAMENT DRIVE GEAR STEPPER  ---------------------------------------------------------------------------------------------
# Note that 'toolhead' & `mmu_gear` endstops will automatically be added if a toolhead sensor or gate sensor is defined
#
# The default values are tested with the ERCF BOM NEMA14 motor. Please adapt these values to the motor you are using
# Example : for NEMA17 motors, you'll usually use higher current
#

#[tmc2209 stepper_mmu_gear]
#uart_pin: mmu:MMU_GEAR_UART
##uart_address: 0 			# Comment out for ERB board
#interpolate: True
#run_current: 0.5			# ERCF BOM NEMA14 motor
#hold_current: 0.1			# Recommend to be small if not using "touch" or move (TMC stallguard)
#sense_resistor: 0.110			# Usually 0.11, 0.15 for BTT TMC2226
#stealthchop_threshold: 0		# Spreadcycle has more torque and better at speed

#
# Uncomment two lines below if you have TMC and want the ability to use filament "touch" homing with gear stepper
#diag_pin: ^mmu:MMU_GEAR_DIAG		# Set to MCU pin connected to TMC DIAG pin for gear stepper
#driver_SGTHRS: 60			# 255 is most sensitive value, 0 is least sensitive

[stepper_mmu_gear]
#rotation_distance: 22.7316868		# Bondtech 5mm Drive Gears. Will be overriden by `mmu_gear_rotation_distance` in mmu_vars.cfg
gear_ratio: 1:1			# ERCF 80:20, Tradrack 50:17
#full_steps_per_rotation: 200		# 200 for 1.8 degree, 400 for 0.9 degree
step_pin: PF9
dir_pin: PF10
enable_pin: !PG2
rotation_distance: 23 # less is faster
microsteps: 16

[tmc2209 stepper_mmu_gear]
uart_pin: PF2
#tx_pin: mmu:PC10
#uart_address: 2
run_current: 0.800
hold_current: 0.100
#stealthchop_threshold: 999999
interpolate: False
#driver_SGTHRS: 50
#diag_pin: mmu:PC1
#driver_SGT: -64  # -64 is most sensitive value, 63 is least sensitive

#
# Uncomment the two lines below to enable filament "touch" homing option with gear motor
#extra_endstop_pins: tmc2209_stepper_mmu_gear:virtual_endstop
#extra_endstop_names: mmu_gear_touch


# SELECTOR STEPPER  --------------------------------------------------------------------------------------------------------
# Consult doc if you want to setup selector for "touch" homing instead or physical endstop
#
#[tmc2209 stepper_mmu_selector]
#uart_pin: mmu:MMU_SEL_UART
##uart_address: 1 			# Comment out for ERB board
#run_current: 0.4			# ERCF BOM NEMA17 motor
#hold_current: 0.2			# Can be small if not using "touch" movement (TMC stallguard)
#interpolate: True
#sense_resistor: 0.110
#stealthchop_threshold: 100		# Stallguard "touch" movement (slower speeds) best done with stealthchop

#
# Uncomment two lines below if you have TMC and want to use selector "touch" movement
#diag_pin: ^mmu:MMU_SEL_DIAG 		# Set to MCU pin connected to TMC DIAG pin for selector stepper
#driver_SGTHRS: 75			# 255 is most sensitive value, 0 is least sensitive

[stepper_mmu_selector]
#step_pin: mmu:MMU_SEL_STEP
#dir_pin: !mmu:MMU_SEL_DIR
#enable_pin: !mmu:MMU_SEL_ENABLE
#rotation_distance: 40
#microsteps: 16 				# Don't need high fidelity
#full_steps_per_rotation: 200		# 200 for 1.8 degree, 400 for 0.9 degree
#endstop_pin: ^mmu:MMU_SEL_ENDSTOP	# Selector microswitch
#endstop_name: mmu_sel_home
step_pin: PG4
dir_pin: PC1
enable_pin: !PA2
rotation_distance: 23 # # less is faster
microsteps: 16

[tmc2209 stepper_mmu_selector]
uart_pin: PC7
#tx_pin: mmu:PC10
#uart_address: 0
run_current: 0.800
hold_current: 0.100
#stealthchop_threshold: 999999
interpolate: False
#driver_SGTHRS: 50
#diag_pin: mmu:PC0
#driver_SGTHRS: 255  # 255 is most sensitive value, 0 is least sensitive tmc2209
#driver_SGT: -64  # -64 is most sensitive value, 63 is least sensitive

#
# Uncomment two lines below to give option of  selector "touch" movement
#extra_endstop_pins: tmc2209_stepper_mmu_selector:virtual_endstop
#extra_endstop_names: mmu_sel_touch


# SELECTOR SERVO -----------------------------------------------------------------------------------------------------------
# Basic servo PWM setup. If these values are changed then the angles defined for different positions will also change
#
#[mmu_servo mmu_servo]
#pin: mmu:PB0 # MMU_SERVO
#maximum_servo_angle: 180
#minimum_pulse_width: 0.00085
#maximum_pulse_width: 0.00215


# OPTIONAL GANTRY SERVO FOR FILAMETRIX FILAMENT CUTTER --------------------------------------------------------------------
# Basic servo PWM setup. If these values are changed then the angles defined for different positions will also change
#
# Uncomment only if you have gantry servo
#
#[mmu_servo mmu_gantry_servo]
#pin: GANTRY_SERVO
#maximum_servo_angle: 180
#minimum_pulse_width: 0.00085
#maximum_pulse_width: 0.00215
#initial_angle: 180


# ENCODER -----------------------------------------------------------------------------------------------------------------
# Encoder measures distance, monitors for runout and clogging and constantly calculates % flow rate
# Note that the encoder_resolution set if is purely a default to get started.  It is set through calibration
# and stored in mmu_vars.cfg
#
#[mmu_encoder mmu_encoder]
#encoder_pin: ^mmu:MMU_ENCODER		# EASY-BRD: ^PA6, Flytech ERB: ^gpio22
#encoder_resolution: 1.0			# This is just a starter value. Overriden by `mmu_encoder_resolution` in mmm_vars.cfg
#desired_headroom: 5.0			# The clog/runout headroom that MMU will attempt to maintain (closest MMU comes to triggering runout)
#average_samples: 4			# The "damping" effect of last measurement. Higher value means clog_length will be reduced more slowly
#flowrate_samples: 20			# How many "movements" on the encoder to measure over for flowrate calc

# FILAMENT SENSORS ---------------------------------------------------------------------------------------------------------
# Define the pins for optional sensors in the filament path. All but the pre-gate sensors will be automatically setup as
# both endstops (for homing) and sensors for visibility purposes.
#
# 'pre_gate_switch_pin_X' .. 'mmu_pre_gate_X` sensor detects filament at entry to MMU. X=gate number (0..N)
# 'toolhead_switch_pin'   .. 'toolhead' sensor detects filament after extruder entry
# 'extruder_switch_pin'   .. 'extruder' sensor detects filament just before the extruder entry
# 'gate_switch_pin'       .. shared 'mmu_gate' sensor detects filament at the gate of the MMU
#
# Uncomment sensors that are fitted. Note: older method of defining toolhead sensor still works but this way is recommended
#
#[mmu_sensors]
#pre_gate_switch_pin_0: mmu:{pre_gate_0_pin}
#pre_gate_switch_pin_1: mmu:{pre_gate_1_pin}
#pre_gate_switch_pin_2: mmu:{pre_gate_2_pin}
#pre_gate_switch_pin_3: mmu:{pre_gate_3_pin}
#pre_gate_switch_pin_4: mmu:{pre_gate_4_pin}
#pre_gate_switch_pin_5: mmu:{pre_gate_5_pin}
#pre_gate_switch_pin_6: mmu:{pre_gate_6_pin}
#pre_gate_switch_pin_7: mmu:{pre_gate_7_pin}
#pre_gate_switch_pin_8: mmu:{pre_gate_8_pin}
#pre_gate_switch_pin_9: mmu:{pre_gate_9_pin}
#pre_gate_switch_pin_10: mmu:{pre_gate_10_pin}
#pre_gate_switch_pin_11: mmu:{pre_gate_11_pin}

#gate_switch_pin: mmu:MMU_GATE_SENSOR
#extruder_switch_pin: toolboard:PB4 # EXTRUDER_SENSOR
#toolhead_switch_pin: TOOLHEAD_SENSOR


## MMU OPTIONAL NEOPIXEL LED SUPPORT ----------------------------------------------------------------------------------------
## Define the led connection, type and length
##
#[neopixel mmu_leds]
#pin: mmu:MMU_NEOPIXEL
#chain_count: 3			# Number gates x1 or x2 + 1 (if you want status)
#color_order: GRBW		# Set based on your particular neopixel specification
#
#
## MMU LED EFFECT SEGMENTS --------------------------------------------------------------------------------------------------
## NOTE IT HARMLESS TO LEAVE THIS SECTION - IT IS INACTIVE UNLESS 'led_strip' can be found by uncommenting [neopixel] above
##
## Define neopixel LEDs for your MMU. The chain_count must be large enough for your defined effect ranges. These ranges are:
##   exit   .. this set of LEDs, one for every gate, usually would be mounted at the exit point of the gate
##   entry  .. this set of LEDs, one for every gate, could be mounted at the entry point of filament into the MMU
##   status .. this single LED represents the status of the currently selected filament, typically  mounted on selection mechanism
##
## Note that all sets are optional. You can opt simple to have just the 'exit' set for example. The advantage to having
## both entry and exit LEDs is that the 'entry'ones can display gate status while the 'exit' one displays the filament color
## 
## The effects requires the installation of Julian Schill's awesome LED effect module: https://github.com/julianschill/klipper-led_effect
## LED's are indexed in the chain from 1..N. Thus to set up LED's on 'exit' and a single 'status' LED on a 4 gate MMU:
##   exit_range:   1-4
##   status_index: 5
## In this example no 'entry' set is configured.
##
## Note the range order is important and depends on your wiring. Thus 1-4 and 4-1 both represent the same LED range but mapped
## to different gates
##
## Happy Hare provides a convenience wrapper [mmu_led_effect] that not only creates an effect on each of the [mmu_leds] specified
## segments but also each individual LED for atomic control.
##
#[mmu_leds]
#num_gates: 2
#led_strip: neopixel:mmu_leds
#exit_range: 1-2
##entry_range: 3-3
#status_index: 3
#frame_rate: 24
#
